﻿using System;
using Microsoft.Practices.Unity;
using System.Web.UI.WebControls;
using System.Web.UI;
using Churchtoolkit.Utils.ErrorProvider;
using Churchtoolkit.DataAccess.Entities;
using Churchtoolkit;
namespace Churchtoolkit.Shell.Views
{
    public partial class RegistrationView : Page<RegistrationViewPresenter>, IRegistrationViewView
    {
        #region [ events ]
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.vldreqFirstName.Replace("[Field]", "First Name");
                this.vldreqDisplayName.Replace("[Field]", "Display Name");
                this.vldreqEmail.Replace("[Field]", "Email");
                this.vldreqPassword.Replace("[Field]", "Password");
            }
        }
        protected void UnavailableMail_Validate(object sender, ServerValidateEventArgs e)
        {
            e.IsValid = this.Presenter.IsUnique(e.Value);
        }
        protected void Register_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                SaveHasSucceded();
                // need to redirect to another page 
            }
        }
        #endregion

        #region [ properties ]
        /// <summary>
        /// Gets the current member.
        /// </summary>
        /// <value>The current member.</value>
        public Members CurrentMember
        {
            get
            {
                return new Members
                {
                    FirstName = this.txtFirstName.Text,
                    LastName = this.txtLastName.Text,
                    DisplayName=this.txtDisplayName.Text,
                    Email = this.txtEmail.Text,
                    Password = this.txtPassword.Text
                };
            }
        }
        #endregion

        #region [ Helper ]
        /// <summary>
        /// Saves the succeded.
        /// </summary>
        /// <returns></returns>
        void SaveHasSucceded()
        {
           Presenter.Save();
        }
        #endregion

    }
}


